package ua.edu.nuos.jeetraining2012.cms.entity;

import javax.persistence.Column;
import javax.persistence.Id;
import java.io.Serializable;

/**
 * Complex primary key class for StudentsToHomeWorkEntity.
 *
 * @author Victor N. Ganichev victor.ganichev@gmail.com
 * @version 1.0 Date: 23.05.13 Time: 23:49
 * @since 1.0
 */
public class StudentsToHomeWorkId implements Serializable {

    /**
     * Student Id.
     */
    @Id
    @Column(name = "student_id")
    private String studentId;

    /**
     * HomeWork Id.
     */
    @Id
    @Column(name = "homework_id")
    private long homeworkId;

    // Default constructor
    public StudentsToHomeWorkId() {}

    /**
     * Overloaded constructor with predefined student id and homework id.
     *
     * @param studentId     Student id.
     * @param homeworkId    Homework ID.
     */
    public StudentsToHomeWorkId(String studentId, long homeworkId) {
        this.studentId = studentId;
        this.homeworkId = homeworkId;
    }

    // Getters & Setters
    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public long getHomeworkId() {
        return homeworkId;
    }

    public void setHomeworkId(long homeworkId) {
        this.homeworkId = homeworkId;
    }

    // Overrides

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        StudentsToHomeWorkId that = (StudentsToHomeWorkId) o;

        if (homeworkId != that.homeworkId) return false;
        if (studentId != null ? !studentId.equals(that.studentId) : that.studentId != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = studentId != null ? studentId.hashCode() : 0;
        result = 31 * result + (int) (homeworkId ^ (homeworkId >>> 32));
        return result;
    }
}
